<?php

namespace app\models;

use yii\db\ActiveRecord;

/**
 * 卡替换
 * Class CardReplace
 * @package app\models
 *
 * @property integer $id PK
 * @property integer $from_card_id 旧卡编号
 * @property integer $to_card_id 新卡编号
 * @property integer $require_sub_uid 申请人子用户编号
 * @property integer $status 状态
 * @property integer $create_time 创建时间
 * @property integer $verify_time 审核时间
 *
 * @property SubUser $subUser 关联子用户
 * @property Card $fromCard 关联旧卡
 * @property Card $toCard 关联新卡
 */
class CardReplace extends ActiveRecord
{
    const STATUS_WAIT = 1;
    const STATUS_COMPLETE = 2;
    const STATUS_REJECTED = 9;

    /**
     * 关联子用户
     * @return \yii\db\ActiveQuery
     */
    public function getSubUser()
    {
        return $this->hasOne(SubUser::class, ['id' => 'require_sub_uid']);
    }

    /**
     * 关联旧卡
     * @return \yii\db\ActiveQuery
     */
    public function getFromCard()
    {
        return $this->hasOne(Card::class, ['id' => 'from_card_id']);
    }

    /**
     * 关联新卡
     * @return \yii\db\ActiveQuery
     */
    public function getToCard()
    {
        return $this->hasOne(Card::class, ['id' => 'to_card_id']);
    }
}
